package Chapter4;

public class Caculer {
    //参与计算的两个数和一个操作符
    private double num1;
    private double num2;
    private String op;
    //有参构造方法
    public Caculer(double num1, double num2, String op) {
        this.num1 = num1;
        this.num2 = num2;
        this.op = op;
    }
    //无参构造方法
    public Caculer() {
    }
    //访问器和设置器  对象使用者修改或调用对象的数据
    public double getNum1() {
        return num1;
    }
    public void setNum1(double num1) {
        this.num1 = num1;
    }

    public String getOp() {
        return op;
    }

    public void setOp(String op) {
        this.op = op;
    }

    public double getResult() {
        return caculate();
    }

    //定义一个private计算的方法
    private double caculate(){
        switch (op){
            case "+":
                num2 += num1;
                break;
            case "-":
                num2 -= num1;
                break;
            case "*":
                num2 *= num1;
                break;
            case "/":
                num2 /= num1;
                break;
        }
        return num2;
    }
}
